package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import po.ComboboxItem;
import po.HardDisk;
import po.Result;
import service.HardDiskService;

import java.util.List;

@Controller
@RequestMapping("/hardDisk")
public class HardDiskController {
    @Autowired
    private HardDiskService hardDiskService;

    @RequestMapping("/getHardDiskInfoView")
    public String getHardDiskInfoView() {
        return "resource/hardDiskInfo";
    }

    @RequestMapping("/findAllHardDisks")
    public @ResponseBody
    List<HardDisk> findAllHardDisks(HardDisk hardDisk) throws Exception {
        return hardDiskService.findAllHardDisks(hardDisk);
    }

    @RequestMapping("/getAddHardDiskView")
    public String getAddHardDiskView() {
        return "resource/addHardDisk";
    }

    @RequestMapping("/addHardDisk")
    public @ResponseBody
    Result addHardDisk(HardDisk hardDisk) {
        return hardDiskService.addHardDisk(hardDisk);
    }

    @RequestMapping("/deleteHardDiskById")
    public @ResponseBody
    Result deleteHardDiskById(int id) {
        return hardDiskService.deleteHardDiskById(id);
    }

    @RequestMapping("/findHardDiskForComb")
    public @ResponseBody
    List<ComboboxItem> findHardDiskForComb() throws Exception {
        return hardDiskService.findHardDiskForComb();
    }

    @RequestMapping("/getEditHardDiskView")
    public String getEditHardDiskView() {
        return "resource/editHardDisk";
    }

    @RequestMapping("/updateHardDisk")
    public @ResponseBody
    Result updateHardDisk(HardDisk hardDisk) {
        return hardDiskService.updateHardDiskById(hardDisk.getId(), hardDisk);
    }
}
